package com.ruoyi.products.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.products.domain.Img;
import com.ruoyi.products.domain.Video;
import com.ruoyi.products.mapper.ImgMapper;
import com.ruoyi.products.mapper.VideoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.products.mapper.ProductMapper;
import com.ruoyi.products.domain.Product;
import com.ruoyi.products.service.IProductService;

/**
 * 选品信息Service业务层处理
 *
 * @author star
 * @date 2025-06-03
 */
@Service
public class ProductServiceImpl implements IProductService
{
    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private VideoMapper videoMapper;

    @Autowired
    private ImgMapper imgMapper;

    /**
     * 查询选品信息
     *
     * @param id 选品信息主键
     * @return 选品信息
     */
    @Override
    public Product selectProductById(Long id)
    {
        Product productData = productMapper.selectProductById(id);
        Img imgParam = new Img();
        imgParam.setProductId(productData.getProductId());
        Video videoParam = new Video();
        videoParam.setProductId(productData.getProductId());
        productData.setImgList(imgMapper.selectImgList(imgParam));
//        productData.setVideoList(videoMapper.selectVideoList(videoParam));

        return productData;
    }

    /**
     * 查询选品信息列表
     *
     * @param product 选品信息
     * @return 选品信息
     */
    @Override
    public List<Product> selectProductList(Product product)
    {
        List<Product> products = productMapper.selectProductList(product);
        //查询选品的图片和视频
        for (Product productData : products) {
            Img imgParam = new Img();
            imgParam.setProductId(productData.getProductId());
            Video videoParam = new Video();
            videoParam.setProductId(productData.getProductId());
            productData.setImgList(imgMapper.selectImgList(imgParam));
            productData.setVideoList(videoMapper.selectVideoList(videoParam));
        }

        return products;
    }

    /**
     * 新增选品信息
     *
     * @param product 选品信息
     * @return 结果
     */
    @Override
    public int insertProduct(Product product)
    {
        product.setCreateTime(DateUtils.getNowDate());
        return productMapper.insertProduct(product);
    }

    /**
     * 修改选品信息
     *
     * @param product 选品信息
     * @return 结果
     */
    @Override
    public int updateProduct(Product product)
    {
        product.setUpdateTime(DateUtils.getNowDate());
        return productMapper.updateProduct(product);
    }

    /**
     * 批量删除选品信息
     *
     * @param ids 需要删除的选品信息主键
     * @return 结果
     */
    @Override
    public int deleteProductByIds(Long[] ids)
    {
        return productMapper.deleteProductByIds(ids);
    }

    /**
     * 删除选品信息信息
     *
     * @param id 选品信息主键
     * @return 结果
     */
    @Override
    public int deleteProductById(Long id)
    {
        return productMapper.deleteProductById(id);
    }
}
